package de.lulusoft.anothertorrent.gui.views.Providers;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

import de.lulusoft.anothertorrent.core.rtorrent.Tracker;
import de.lulusoft.anothertorrent.gui.util.Util;

public class TrackerTableLabelProvider implements ITableLabelProvider {

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		if (element instanceof Tracker)
		{
			Tracker t = (Tracker)element;
			switch (columnIndex)
			{
			case 0: return t.getUrl();
			case 1: if (t.getScrape_time_last() == 0L)
						return "Never";
					DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm");
					return df.format(new Date(t.getScrape_time_last() * 1000)); // convert seconds to milliseconds
			case 2: return ((Integer)Math.round(t.getNormal_interval() / 60)).toString();
			case 3: return t.getScrape_complete().toString();
			case 4: return Util.formatBoolean(t.getEnabled());
			case 5: return t.getGroup();
			case 6: return t.getId();
			case 7: return t.getType().toString();
			case 8: return Util.formatBoolean(t.getOpen());
			
			default: return "Not yet implemented";
			}
		}
		return "";
	}

	@Override
	public void addListener(ILabelProviderListener listener) {
	}

	@Override
	public void dispose() {
	}

	@Override
	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener) {
	}

}
